{extend name="common/base"/}
<!-- 样式 -->
{block name="style"}
  <style>
    .layui-form-label{
        width: 120px;
    }
	.layui-input-block{
		margin-left: 150px;
	}
	</style>
  <link rel="stylesheet" href="__ADMIN__/module/dtree/dtree.css">
  <link rel="stylesheet" href="__ADMIN__/module/dtree/font/dtreefont.css">
{/block}
<!-- /样式 -->
<!-- 主体 -->
{block name="body"}
<form class="layui-form vae-content">
	<div class="layui-form-item">
		<label class="layui-form-label">离职人员</label>
		<div class="layui-input-block">
			<input type="hidden" name="uid" lay-verify="required" autocomplete="off">
			<input type="text" name="name" placeholder="请输选择离职人员" lay-verify="required" autocomplete="off" readonly class="layui-input" style="max-width: 500px;">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">所在部门</label>
		<div class="layui-input-block">
			<input type="text" name="department" lay-verify="required" autocomplete="off" class="layui-input" readonly style="max-width: 500px;">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">离职日期</label>
		<div class="layui-input-block">
			<input type="text" id="quit_time" name="quit_time" lay-verify="required" autocomplete="off" placeholder="请选择离职日期" readonly class="layui-input" style="max-width: 500px;">
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">离职原因</label>
		<div class="layui-input-block">
			<textarea name="remark" placeholder="请输入离职原因" lay-verify="required" class="layui-textarea" style="max-width: 500px;"></textarea>
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">部门负责人</label>
		<div class="layui-input-block">
			<input type="text" name="lead_admin_name" autocomplete="off" lay-verify="required" placeholder="请选择部门负责人" readonly class="layui-input" class="layui-input" style="max-width: 500px;">
			<input type="hidden" name="lead_admin_id" autocomplete="off" lay-verify="required">
		</div>
	</div>
	<div  class="layui-form-item layui-form-text">
		<label class="layui-form-label">交接人员</label>
		<div class="layui-input-block">
			<input type="text" name="connect_names" autocomplete="off" lay-verify="required" placeholder="请选择交接人员" readonly class="layui-input" style="max-width: 500px;">
			<input type="hidden" name="connect_uids" autocomplete="off" class="layui-input" lay-verify="required" style="max-width: 500px;">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden" name="id" value="0">
			<button class="layui-btn" lay-submit="" lay-filter="vaeform">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			<button lay-event="back" class="layui-btn layui-btn-primary">返回</button>
		</div>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
var did = {$did};
	function init(layui) {
		var form = layui.form
			, layer = layui.layer
			, laydate = layui.laydate
			,employeepicker = layui.employeepicker;

		laydate.render({
			elem: '#quit_time'
		});

		$('.vae-content').on('click','[name="department"]',function(){
			var val=$(this).val();
			if(val==''){
				layer.msg('请先选择需要离职的人员');
			}			
		});
		
		//选择员工弹窗	
		$('.vae-content').on('click','[name="name"]',function () {
			var ids=$('[name="uid"]').val(),names=$('[name="name"]').val(),departments=$('[name="department"]').val();
			employeepicker.init({
				ids:ids,
				names:names,
				departments:departments,
				type:0,
				callback:function(ids,names,dids,departments){
					if(dids == did){
						$('[name="uid"]').val(ids);
						$('[name="name"]').val(names);
						$('[name="department"]').val(departments);
					}
					else{
						setTimeout(function(){
							layer.msg('只能添加自己分所的员工');
						},1)
					}
				}
			});
		}); 



		//监听部门负责人
		$('.vae-content').on('click','[name="lead_admin_name"]',function () {
			var ids=$('[name="lead_admin_id"]').val(),names=$('[name="lead_admin_name"]').val();
			employeepicker.init({
				ids:ids,
				names:names,
				type:0,
				callback:function(ids,names,dids,departments){
					if(dids == did){
						$('[name="lead_admin_id"]').val(ids);
						$('[name="lead_admin_name"]').val(names);
					}
					else{
						setTimeout(function(){
							layer.msg('只能添加自己分所的员工');
						},1)
					}
				}
			});
		}); 

		//选择交接成员
		$('[name="connect_names"]').on('click',function(){
			var ids=$('[name="connect_uids"]').val(),names=$('[name="connect_names"]').val(),idsArray=[],namesArray=[];
			if(ids!=''){
				idsArray=ids.split(',');
				namesArray=names.split(',');
			}
			employeepicker.init({
				ids:idsArray,
				names:namesArray,
				callback:function(ids,names){
					$('[name="connect_uids"]').val(ids.join(',')),
					$('[name="connect_names"]').val(names.join(','));
				}
			});
		});

		//监听提交
		form.on('submit(vaeform)', function (data) {
			$.ajax({
				url: "/admin/personal/department_quit_save",
				type: 'post',
				data: data.field,
				success: function (e) {
					if (e.code == 1) {
						layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
							history.back(-1);
							layer.close(index);
						});
					} else {
						layer.msg(e.msg);
					}
				}
			})
			return false;
		});
		//监听返回
		$('.vae-content').on('click','[lay-event="back"]',function () {
			history.back(-1);
			return false;
		});
	}

</script>
{include file="common/layui" base='base' extend="['employeepicker']" use="['form','employeepicker','layer','laydate']" callback="init" /}
{/block}
<!-- /脚本 -->